package cms.simmytech.util;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpResultUtil {

	public static void responseJS(HttpServletRequest request, HttpServletResponse response, String msg, int state) {
		try {
			String requestType = request.getHeader("X-Requested-With");
			if ("XMLHttpRequest".equals(requestType)) {
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				response.setStatus(state);
				PrintWriter pw = response.getWriter();
				pw.write("没有访问权限");
			} else {
				response.setHeader("Content-type", "text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				response.setStatus(state);
				PrintWriter pw = response.getWriter();
				pw.write("<script>alert('" + msg + "');</script>");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
